#include <bits/stdc++.h>

using namespace std;

string sameNumber(vector<int> &nums, int k)
{
    // Write your code here
    for(int i = 0; i < nums.size() - 1; i++){
        for(int j = i + 1; j < nums.size(); j++){
            if(nums[i] == nums[j] && j - i < k){
                printf("%d %d %d", i, j, nums[i]);
                return "YES";
            }
        }
    }
    return "NO";
}

int main()
{
    vector<int> nums = {1,2,3,1,5,9,3};
    cout << sameNumber(nums, 4) << endl;
    nums = {1,2,3,5,7,1,5,1,3};
    cout << sameNumber(nums, 4) << endl;
    nums = {464,779,518,851,512,845,926,214,821,145,867,664,479,236,1,157,672,765,950,723,258,128,530,226,390,106,965,810,637,302,526,205,940,509,95,250,561,488,295,747,624,41,660,708,477,77,823,654,7,485,967,586,489,38,211,105,789,904,380,799,151,484,785,331,700,964,626,213,211,714,716,284,832,800,37,221,243,88,41,235,918,254,846,155,188,246,214,159,375,608,73,110,494,49,360,571,304,853,954,479};
    cout << sameNumber(nums, 4) << endl;
    return 0;
}

/**
 1368. 相同数字

给一个数组，如果数组中存在相同数字，且相同数字的距离小于给定值k，输出YES，否则输出NO。
注意事项

    输入的数组长度为n，保证n <= 100000。
    数组元素的值为x，0 <= x <= 1e9。
    输入的k满足 1 <= k < n。

您在真实的面试中是否遇到过这个题？
样例

给出 array = [1,2,3,1,5,9,3], k = 4, 返回 "YES"。

解释：
index为3的1和index为0的1距离为3，满足题意输出YES。

给出 array =[1,2,3,5,7,1,5,1,3], k = 4, 返回 "YES"。

解释：
index为7的1和index为5的1距离为2，满足题意。
*/
